package com.nantai.jiafang.nantaijiafang.activity.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.nantai.jiafang.nantaijiafang.R;

import java.util.ArrayList;

/**
 * Created by Administrator on 2017/10/9.
 */

    public class Login_select_adapter  extends ArrayAdapter<String> {
        private int resourceId;
        public Login_select_adapter(Context context, int textViewResourceId,
                                    ArrayList<String> objects) {
            super(context, textViewResourceId, objects);
            resourceId = textViewResourceId;
        }
        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            String name = getItem(position); // 获取当前项的Fruit实例
            View view ;
            ViewHolder viewHolder;
            if (convertView == null) {                //判断是否有过缓存
                view = LayoutInflater.from(getContext()).inflate(resourceId, null);
                viewHolder = new ViewHolder();
                viewHolder.name = (TextView) view.findViewById
                        (R.id.name);
                view.setTag(viewHolder);                  //  将ViewHolder 存储在View 中
            } else {
                view = convertView;
                viewHolder = (ViewHolder) view.getTag(); //  重新获取ViewHolder
            }
            viewHolder.name.setText(name);
            return view;
        }
        class ViewHolder {
            TextView name;
        }
    }

